package com.db.williamchart.data;

import android.graphics.LinearGradient;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;

public class Frame {

    private float left;
    private float top;
    private float right;
    private float bottom;

    public Frame(float left, float top, float right,float bottom) {
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
    }

    public Rect toRect() {
        Rect rect = new Rect((int)left, (int)top, (int)right, (int)bottom);
        return rect;
    }

    public RectF toRectF() {
        return new RectF(left, top, right, bottom);
    }

    public Frame withPaddings(Paddings paddings) {
        return new Frame(left + paddings.getLeft(),
                top + paddings.getTop(),
                right - paddings.getRight(),
                bottom - paddings.getBottom());
    }

    public LinearGradient toLinearGradient(int startColor, int endColor) {
        return new LinearGradient(
                left,
                top,
                left,
                bottom,
                startColor,
                endColor,
                Shader.TileMode.MIRROR
        );
    }

    public boolean contains(float x, float y) {
        return left < right && top < bottom &&
                x >= left && x < right && y >= top && y < bottom;
    }

    public float getLeft() {
        return left;
    }

    public void setLeft(float left) {
        this.left = left;
    }

    public float getTop() {
        return top;
    }

    public void setTop(float top) {
        this.top = top;
    }

    public float getRight() {
        return right;
    }

    public void setRight(float right) {
        this.right = right;
    }

    public float getBottom() {
        return bottom;
    }

    public void setBottom(float bottom) {
        this.bottom = bottom;
    }
}
